<style lang="less">
	@import "../../../assets/style/xinzheng.less";
</style>
<template>
	<div class="xinzheng" ref="validateForm">
		<van-cell-group class="mt10">
			<section class="van-doc-demo-block">
				<h5 class="van-doc-demo-block-title">审核信息详情</h5>
				<van-cell-group class="mt10">
					<van-cell v-for="(item,index) in listDataArr" :title="item.title" :value="item.value" />
				</van-cell-group>
			</section>
			
			<section class="van-doc-demo-block">
				<h5 class="van-doc-demo-block-title">审核信息详情</h5>
				<!--待审核-->
				<van-cell-group class="mt10" v-if="isShow">
					<van-field label="隐患位置" @blur="changeParams('qxPosition',$event)" class="detail_item" v-model="formItem.qxPosition" type="textarea" placeholder="请输入" rows="3" autosize required/>
					
					<van-field label="火灾来源" class="select_item" center icon="arrow" placeholder="请选择" @click-icon="jianzhuShow = true" required disabled v-model="formItem.yhDangerName"/>
					<van-popup v-model="jianzhuShow" position="bottom">
						<van-picker show-toolbar :columns="yhDanger" @confirm="onChangeYH" @cancel="jianzhuShow = false" />
					</van-popup>
		
					<van-field label="数量(处)" @blur="changeParams('yhNumber',$event)" v-model.number="formItem.yhNumber" center placeholder="请输入" required/>
					<van-field label="隐患描述" @blur="changeParams('yhDescription',$event)" class="detail_item" v-model="formItem.yhDescription" type="textarea" placeholder="请输入" rows="4" autosize required/>
		
					<van-field label="风险等级" class="select_item" v-model="formItem.yhRiskLevelName" center icon="arrow" placeholder="请选择" @click-icon="levelshow = true" required disabled/>
					<van-popup v-model="levelshow" position="bottom">
						<van-picker show-toolbar :columns="yhRiskLevel" @confirm="onChangeLevel" @cancel="levelshow = false" />
					</van-popup>
		
					<van-field label="风险描述" @blur="changeParams('yhRiskDescription',$event)" class="detail_item" v-model="formItem.yhRiskDescription" type="textarea" placeholder="请输入" rows="4" autosize required/>
					<van-field label="当前措施" @blur="changeParams('yhCurrentMeasures',$event)" v-model="formItem.yhCurrentMeasures" center placeholder="请输入" required/>
				</van-cell-group>
				<!--已审核-->
				<van-cell-group class="mt10" v-if="!isShow">
					<van-cell v-for="(item,index) in listDataArr2" :title="item.title" :value="item.value" />
				</van-cell-group>
			</section>
		</van-cell-group>
	</div>
</template>

<script>
	import {
		Row,
		Col,
		Cell,
		CellGroup,
		Field,
		Button,
		Icon,
		SwitchCell,
		Popup,
		Picker,
		Switch,
		Toast,
		Dialog
	} from 'vant';
	import { callData } from '../../../axios/axios';
	import AsyncValidator from "async-validator";
	export default {
		name: 'shuzhangXinZheng',
		components: {
			[Cell.name]: Cell,
			[CellGroup.name]: CellGroup,
			[Field.name]: Field,
			[Switch.name]: Switch,
			[Popup.name]: Popup,
			[Picker.name]: Picker,
			[Button.name]: Button,
			[Icon.name]: Icon,
			[SwitchCell.name]: SwitchCell
		},
		data() {
			return {
				listDataArr: [],
				listDataArr2: [],
				getParamsObject: {},
				isShow: true,
				jianzhuShow: false,
				sourceShow: false,
				levelshow: false,
				statusShow: false,
				checked2: false,
				yhRiskLevel: [ //0正常/1关注/2严重
					{text: "正常",ID:0},
					{text: "关注",ID:1},
					{text: "严重",ID:2}
				],
				yhStatus: [ //0未处理/ 1已受控/ 2已闭环
					{text: "未处理",ID:0},
					{text: "已受控",ID:1},
					{text: "已闭环",ID:2}
				],
				yhSource: [
					'请选择', '遗留', '新增'
				],
				yhDanger: [], //调接口，pid传类别的ID可获取数组
				otherItem: {
					yhDangerName: ''
				},
				formItem: {
					lineId: '', //线路名称
					towerId: '', //运行塔号
					qxPosition: '', //缺陷位置
					yhLb: '', //隐患类别
					yhDanger: '', //造成隐患的物体(火灾来源)
					yhNumber: '', //数量(处)
					yhDescription: '', //隐患描述
					yhRiskLevel: '', //风险等级
					yhRiskDescription: '', //风险描述
					yhCurrentMeasures: '', //当前措施
					defectType: 2 //// 1 消缺 2 新增(进来默认是不选状态即2新增)
				},
				rules: {
					qxPosition: {
						required: true,
						message: '隐患位置不可为空'
					},
					yhDanger: {
						required: true,
						message: '火灾来源不可为空'
					},
					yhNumber: [{
							required: true,
							message: '数量不可为空'
						},
						{
							type: 'number',
							message: '数量必须为数字值'
						}
					],
					yhDescription: {
						required: true,
						message: '隐患描述不可为空'
					},
					yhRiskLevel: {
						required: true,
						message: '风险等级不可为空'
					},
					yhRiskDescription: {
						required: true,
						message: '风险描述不可为空'
					},
					yhCurrentMeasures: {
						required: true,
						message: '当前措施不可为空'
					}
				}
			}
		},
		props: {
			xgListArr: {
				type: Object,
				default() {
					return {}
				}
			}
		},
		methods: {
			// 监控输入框的改变并赋值
			changeParams(name,val){
				let getVal = val.target.value
				this.getParamsObject[name] = getVal
				this.getThisParams()
			},
			// 火灾来源
			onChangeYH(val) {
				this.getParamsObject.yhDanger = val.ID
				this.getThisParams()
				this.formItem.yhDangerName = val.text
				this.jianzhuShow = false
			},
			// 风险等级
			onChangeLevel(val) {
				this.getParamsObject.yhRiskLevel = val.ID
				this.getThisParams()
				this.formItem.yhRiskLevelName = val.text
				this.levelshow = false
			},
			//根据不同类别id获取相应的数据
			getYhDanger() {
				var params = {
					pid: this.xgListArr.pid
				}
				callData('/accountServer/CmYhLb/findCmYhLb', 'get', params).then(data => {
					if(data.data) {
						data.data.forEach((item, index) => {
							item.text = item.YH_NAME
						})
					}
					this.yhDanger = data.data
					this.formatProps()
				})
			},
			// 处理传过来的数据
			formatProps(){
				let data = this.xgListArr.data
				let hzlyName = null,
					fxdjName = data.YH_RISK_LEVEL == 0 ? '正常': data.YH_RISK_LEVEL == 1 ? '关注':'严重',
					shztName = data.REVIEW_STATUS == 0 ? "审核中":data.REVIEW_STATUS == 1 ? "通过":"不通过";
				let hzly = this.yhDanger
				hzly.forEach((item,indedx) => {
					if(item.ID == data.YH_DANGER) hzlyName = item.YH_NAME
				})
				
				// 审核信息详情
				let listData = [
					{title:"线路名称",value:data.LINE_NAME_PY},
					{title:"运行杆塔",value:data.TOWER_NAME},
					{title:"隐患类别",value:data.CM_YH_NAME},
					{title:"护线人员",value:data.REALNAME},
					{title:"护线人员电话",value:data.PHONE},
					{title:"审核状态",value:shztName}
				]
				this.listDataArr = listData
				// 审核信息确认
				if(this.isShow){
					this.formItem = {
						qxPosition: data.QX_POSITION, //缺陷位置
						yhDescription: data.YH_DESCRIPTION, //隐患描述
						yhRiskLevelName: fxdjName, //风险等级【//0正常/1关注/2严重】
						yhRiskDescription: data.YH_RISK_DESCRIPTION, //风险描述
						yhCurrentMeasures: data.YH_CURRENT_MEASURES, //当前措施
						yhNumber: data.YH_NUMBER, //数量(处)
						yhDangerName: hzlyName, //造成隐患的物体(火灾来源)
						defectType: 2 //// 1 消缺 2 新增(进来默认是不选状态即2新增)
					}
				}else{
					let listData2 = [
						{title:"隐患位置",value:data.QX_POSITION},
						{title:"火灾来源",value:hzlyName},
						{title:"数量(处)",value:data.YH_NUMBER},
						{title:"隐患描述",value:data.YH_DESCRIPTION},
						{title:"风险等级",value:fxdjName},
						{title:"风险描述",value:data.YH_RISK_DESCRIPTION},
						{title:"当前措施",value:data.YH_CURRENT_MEASURES}
					]
					this.listDataArr2 = listData2
				}
			},
			// 拿到修改的数据
			getThisParams() {
				this.$emit('getParams', this.getParamsObject)
			},
			isShowList(){
				if(this.$route.query.active == 1) this.isShow = false
				else this.isShow = true
			}
		},
		mounted() {
			this.isShowList()
			this.getYhDanger();
		}
	}
</script>